package com.pro.common.service.user.service.unit;

import com.pro.common.api.user.model.db.UserBatchDetail;
import com.pro.common.api.user.model.db.UserBatchInfo;
import com.pro.common.service.user.dao.UserBatchInfoDao;
import com.pro.common.service.user.service.UserBatchDetailService;
import com.pro.common.service.user.service.UserBatchInfoService;
import com.pro.framework.mybatisplus.BaseService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 采集任务服务
 */
@Service
@Slf4j
@AllArgsConstructor
public class UserBatchUnitService {
    private UserBatchInfoService userBatchInfoService;
    private UserBatchDetailService userBatchDetailService;

    public void saveBatch(List<UserBatchInfo> list) {
        userBatchInfoService.saveBatch(list);
        userBatchDetailService.saveBatch(list.stream()
                .filter(o -> o.getUserBatchDetails() != null)
                .flatMap(o -> o.getUserBatchDetails().stream().peek(d -> d.setBatchId(o.getId()))).toList());
    }
}
